package com.hgcode.platform.web;

import com.alibaba.fastjson.JSON;
import com.hgcode.platform.entity.User;
import com.hgcode.platform.rocketmq.producer.OrderProducer;
import jodd.util.RandomString;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RequestMapping("/api/rocketmq")
@RestController
public class RocketMqResource {

    @Resource
    private OrderProducer orderProducer;

    @PostMapping("/push")
    public void push(@RequestBody User user) throws Exception {
        orderProducer.sendMessage(JSON.toJSONString(user));
    }


    @GetMapping("/batchpush")
    public void push() throws Exception {
        for(int i=0;i<100000;i++){
            User user=new User();
            user.setId(Long.parseLong(RandomStringUtils.randomNumeric(5)));
            user.setAge(Integer.parseInt(RandomString.getInstance().randomNumeric(2)));
            user.setName(RandomString.getInstance().randomAlpha(5));
            orderProducer.sendMessage(JSON.toJSONString(user));
        }

    }
}
